package cn.buaa.edu.cn.ffmpegservice.controller;

import cn.buaa.edu.cn.ffmpegservice.config.JsonResult;
import cn.buaa.edu.cn.ffmpegservice.domain.dto.RecordRequest;
import cn.buaa.edu.cn.ffmpegservice.service.IRecordService;
import cn.buaa.edu.cn.ffmpegservice.service.IVerifyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/record")
@RestController
@RequiredArgsConstructor
public class RecordController {


    private final IRecordService recordService;
    private final IVerifyService verifyService;
    @RequestMapping(value = "/begin", method = RequestMethod.POST)
    public JsonResult<?> beginRecord(@RequestBody RecordRequest recordRequest){
        String validStr = recordRequest.getValid();
        if(!verifyService.verifyIdentity(validStr)){
            return  new JsonResult<>("Unauthenticated","User does not have permission");
        }

        String instanceId  = recordRequest.getId();
        return  recordService.beginRecord(instanceId);

    }

    @RequestMapping(value = "/end", method = RequestMethod.POST)
    public JsonResult<?> endRecord(@RequestBody RecordRequest recordRequest){
        String validStr = recordRequest.getValid();
        if(!verifyService.verifyIdentity(validStr)){
            return  new JsonResult<>("Unauthenticated","User does not have permission");
        }

        String instanceId  = recordRequest.getId();
        return recordService.endRecord(instanceId);
    }
}
